package com.gujiangbo.application.common.trace;

import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;

public class InstanceLoader {
	public static <I> I loader(Class<I> clazz)
	  {
	    ServiceLoader<I> serviceLoader = ServiceLoader.load(clazz);
	    if (serviceLoader.iterator().hasNext()) {
	      return (I)serviceLoader.iterator().next();
	    }
	    return null;
	  }
	  
	  public static <T> List<T> loaderServices(Class<T> clazz)
	  {
	    ServiceLoader<T> serviceLoader = ServiceLoader.load(clazz);
	    List<T> services = new ArrayList();
	    for (T service : serviceLoader) {
	      services.add(service);
	    }
	    return services;
	  }
}
